<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="车牌号：">
              <el-select v-model="form.cph" placeholder="请选择" filterable clearable>
                <el-option
                  v-for="item in form.cphList"
                  :key="item.index"
                  :label="item.LicensePlate"
                  :value="item.LicensePlate"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="报警类型：">
              <el-select v-model="form.alermTypeValue" placeholder="请选择">
                <el-option
                  v-for="item in form.alermTypeList"
                  :key="item.label"
                  :label="item.label"
                  :value="item.label"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：">
              <el-date-picker
                v-model="form.StartDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期：">
              <el-date-picker
                v-model="form.EndDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <!-- {"ID":36956,"VID":1313,"TYPE":2,"TIME":"2021-06-09T16:53:52","LONGITUDE":117.30516401713109,"LATITUDE":39.09029332929277
    ,"SPEED":1.5,"LOCATION":"","LICENSE_PLATE":"津C8A221(张贵庄)","SIMCARD_NO":"14702224224","FLENGTH":null,"FOFFSET":null,"FPATH":null,"cmsserver":null} -->
    <el-table v-loading="loading" :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" highlight-current-row>
      <el-table-column prop="VID" label="车辆ID" align="center"  width="100"></el-table-column>
      <el-table-column prop="LICENSE_PLATE" label="车辆名称" align="center"></el-table-column>
      <el-table-column prop="TYPENAME" label="报警类型" align="center"></el-table-column>
      <el-table-column prop="LOCATION" label="地址" align="center"></el-table-column>
      <el-table-column prop="TIME" label="时间" align="center" width="170"></el-table-column>
      <el-table-column prop="SPEED" label="当时时速" align="center"></el-table-column>
      <el-table-column prop="无" label="处理状态" align="center" width="170"></el-table-column>
      <el-table-column prop="无" label="确认人员" align="center" width="170"></el-table-column>
      <el-table-column prop="无" label="确认时间" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'

import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {

    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        cphList: [],//车牌号列表
        cph: '全部',//车牌号
        alermTypeList: [{ label: '全部', value: '0' }, { label: '超速报警', value: '1' }, { label: '停留报警', value: '2' }, { label: '出区域报警', value: '3' }, { label: '未定义报警类型', value: '4' }],
        alermTypeValue: '全部',
        StartDate: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        EndDate: formatDate(new Date(), 'yyyy-MM-dd'),
      },
      originalData: [],
      tableData: [],
      loading: false,
    }
  },
  created () {
  },
  mounted () {
    this.getlistdata()
    this.getLisencePlateList()
  },
  methods: {
    //获取车牌列表
    async getLisencePlateList () {
      var url = '/DataListCompany/GetLisencePlateApi?ClientNo=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      this.form.cphList = data
      this.form.cphList.unshift({ "LicensePlate": "全部" })
    },
    async getlistdata () {
      this.loading = true
      // var url = 'Vehicle/GetAlarmInfo?ClientNo=0000009&TopNum=50&StartDate=2021-06-01&EndDate=2021-06-10'
      var url = 'RubbishVehicle/GetAlarmInfo?StartDate=' + this.form.StartDate + '&EndDate=' + this.form.EndDate + '&TopNum=500&ClientNo=' + localStorage.getItem('CLIENT_NO')
      const { data } = await this.$Http.get(url)
      data.forEach(element => {
        element.TIME = element.TIME.replace('T', ' ')
        switch (element.TYPE) {
            case 1:
                element.TYPENAME = "超速报警";
                break;
            case 2:
                element.TYPENAME = "停留报警";
                break;
            case 3:
                element.TYPENAME = "出区域报警";
                break;
            default:
                element.TYPENAME = "未定义报警类型";
                break;
        }
      });
      // 原始数据
      this.originalData = data
      // console.log(data)
      this.loading = false
      this.personQuery()
    },
    // 人员管理查询
    personQuery () {
      this.currentPage = 1;
      this.tableData = this.originalData
      // const { name, client } = this.form
      if (this.form.cph != '全部') this.tableData = this.tableData.filter(item => item.LICENSE_PLATE.includes(this.form.cph))
      if (this.form.alermTypeValue != '全部') this.tableData = this.tableData.filter(item => this.form.alermTypeValue === item.TYPENAME)
    },
    // 导出Excel
    exportExcel () {
      let excelName = '报警信息'
      const  filterVal = ['VID', 'LICENSE_PLATE', 'TYPENAME','LOCATION', 'TIME', 'SPEED','无', '无', '无']
      const tHeader = ['车辆ID', '车辆名称', '报警类型', '地址','时间', '当时时速', '处理状态', '确认人员','确认时间']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}

</style>